package com.dys.controller;

import com.dys.pojo.Player;
import com.dys.service.PlayerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @className: com.dys.controller.PlayerController
 * @description: com.dys.controller
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/10/30 23:31
 */
@Controller
public class PlayerController {
    @Autowired
    private PlayerService playerService;

    @RequestMapping("/addPlayer")
    public String addPlayerInfo(Player player) {
        // 调用服务层方法,将数据保存进入数据库
        int count = playerService.addPlayer(player);
        System.out.println("受影响行数；" + count);
        // 页面跳转至player信息展示页
        return "redirect:/html/showPlayer.html";
    }

    @RequestMapping("/addPlayer2")
    public String addPlayerInfo2(Player player) {
        // 调用服务层方法,将数据保存进入数据库
        int count = playerService.addPlayer(player);
        System.out.println("受影响行数；" + count);
        // 页面跳转至player信息展示页
        return "redirect:/showPlayer.jsp";
    }

    @ResponseBody
    @RequestMapping("/listPlayers")
    public List<Player> listPlayers() {
        List<Player> list = playerService.getPlayers();
        return list;
    }
}
